package com.flame.parameter.service;

import java.util.List;

import com.flame.parameter.controller.vo.ParamsVo;
import com.flame.parameter.entity.Params;
import com.flame.parameter.exception.ParameterExceptionMessage;
import com.flame.parameter.exception.ParameterRuntimeException;
import com.flame.parameter.mapper.ParamsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wuxintong
 * @since 2022/10/26
 */
@Service
public class ParamsService {

    @Autowired
    private ParamsMapper paramsMapper;

    public List<Params> pageParams(ParamsVo paramsVo) {
        return paramsMapper.page(paramsVo);
    }

    public void addParams(Params params) {
        Params param = paramsMapper.selectById(params.getParamCode());
        if (param != null) {
            throw new ParameterRuntimeException(ParameterExceptionMessage.PARAM_EXIST, params.getParamCode());
        }
        paramsMapper.insert(params);
    }

    public void updateParams(Params params) {
        paramsMapper.updateById(params);
    }

    public void deleteParams(String paramCode) {
        paramsMapper.deleteById(paramCode);
    }

    public List<String> queryParamsGroup() {
        return paramsMapper.listParamsGroup();
    }

    public String getParamsValue(String paramCode) {
        return paramsMapper.getParamValue(paramCode);
    }
}
